package demo5;

import java.util.Arrays;

public class Test {

    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int ret = 0;
        //先固定一个最大的数
        for (int i = nums.length - 1; i >= 2; i--) {
            int left = 0, right = i - 1;
            while (left < right) {
                if (nums[left] + nums[right] > nums[i]) {
                    ret += right - left;
                    right--;
                }else {
                    left++;
                }
            }
        }
        return ret;
    }

    public int[] twoSum(int[] price, int target) {
        int left = 0, right = price.length - 1;
        while (left < right) {
            int sum = price[left] + price[right];
            if (sum < target) {
                left++;
            }else if(sum > target){
                right--;
            }else {
                return new int[]{price[left], price[right]};
            }
        }
        return new int[]{0};
    }

    public static void main(String[] args) {

    }

}
